<template>
  <div class="user1-page">
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="关键词：">
          <el-input v-model="searchParams.queryName" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-box">
      <el-table
        v-loading="loading"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="selection" width="80px" align="center" />
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="批文附件" fixed="right" width="120px">
          <template slot-scope="scope">
            <span @click="godownload(scope.row.file,scope.row.enclosureName)">查看</span>
            <!-- <ClickDownload :file="scope.row.file"/> -->
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import {http_project2} from "@/api"
import { downloadFile } from '@/utils/request'
import axios from 'axios'
import jsonp from 'vue-jsonp'
export default {
  name: 'Index',
  mixins: [crud],
  props: {
    currentDetail: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      request: {
        page: http_project2.cailiaoPage
      },
      searchParams: {
        queryName: ''
      },
      columns: [
        { prop: 'projectCode', label: '项目代码' },
        { prop: 'approvalItemid', label: '办件编号' },
        { prop: 'materialItems', label: '材料名称' },
        { prop: 'enclosureName', label: '文件名称' },
      ],
      tableData: []
    }
  },
  mounted() {
  // 将callbackFun方法绑定到window对象
    window['callbackFun'] = (data) => {
      cosole.log('定义的回调函数')
    }
  // 假设返回的为callbackFun.ajax_callback()
  // window['callbackFun'] = {
  //   ajax_callback: function (res) {
  //     cosole.log('定义的回调函数')
  //   }
  // }
  },
  methods: {
    
    getQueryParams() {
      const params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize
      }
      return {
        ...params,
        ...this.searchParams,
        projectCode: this.currentDetail.projectCode
      }
    },
    godownload(url , name) {
      let data = "<textarea style='width:100% ; height=300px'>{文件下载地址:http://59.202.42.251/zxptv3zsoss/2022/08/e2b9303cabf64bac975f752f89c7c4ef/0dd053dbe11f499a8e75c9b6c23cc2de/7c69c23adba84deeb65416efef8eb913.dwg?Expires=1681454374&OSSAccessKeyId=vMEEKZ8oBXTbrWER&Signature=KbVY4lJP%2Fj2n8mv%2F7cJVzRjGAH4%3D}</textarea>"
      console.log(data.split('}')[0].split('文件下载地址:')[1]);
      // console.log(url)
      window.open('http://59.202.42.251/zxptv3zsoss/2022/08/e2b9303cabf64bac975f752f89c7c4ef/0dd053dbe11f499a8e75c9b6c23cc2de/7c69c23adba84deeb65416efef8eb913.dwg?Expires=1681454374&OSSAccessKeyId=vMEEKZ8oBXTbrWER&Signature=KbVY4lJP%2Fj2n8mv%2F7cJVzRjGAH4%3D', '_self')

      // this.downloadFile2('http://59.202.42.251/zxptv3zsoss/2022/08/e2b9303cabf64bac975f752f89c7c4ef/0dd053dbe11f499a8e75c9b6c23cc2de/7c69c23adba84deeb65416efef8eb913.dwg?Expires=1681454374&OSSAccessKeyId=vMEEKZ8oBXTbrWER&Signature=KbVY4lJP%2Fj2n8mv%2F7cJVzRjGAH4%3D', name.split('.')[0])
      this.$jsonp(url, {
      }).then((res) => {
        console.log(res)
        alert("11")
        downloadFile(res.split('}')[0].split('文件下载地址:')[1], name.split('.')[0])

      })
    },
    downloadFile2(url, fileName) {
      let data = url.split('?')[1].split('&')
      let params = {}
      data.forEach(element => {
        params[element.split('=')[0]]=element.split('=')[1]
      });
      return
      const a = document.createElement('a')
      // alert(url)
      console.log(params);
      this.$jsonp(url.split('?')[0],{...params}).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
        a.href = URL.createObjectURL(blob)
        console.log(a.href)
        a.download = fileName
        // a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
        document.body.appendChild(a)
        a.click()

        // 在资源下载完成后 清除 占用的缓存资源
        window.URL.revokeObjectURL(a.href)
        document.body.removeChild(a)
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
